
//
//  UIBarButton+Extension.swift
//  0319iOSweiboDemo
//
//  Created by Tang on 16/3/24.
//  Copyright © 2016年 大天朝. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //便利构造函数.便利构造函数必须指定构造函数来创建对象.也可以调用便利构造函数.实际上内容它调用了指定构造函数
    convenience init(imageName: String, targer: AnyObject?, action: Selector?) {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        //按钮的点击事件
        button.addTarget(targer, action: action!, forControlEvents: UIControlEvents.TouchUpInside)
        self.init(customView: button)
    }
    /**
     创建带按钮的UIBarButonItem
     
     :param: imageName 图片名称
     
     :returns: UIBarButonItem
     */
//    class func createBarButtonItem(imageName: String) -> UIBarButtonItem {
//        let button = UIButton()
//        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
//        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
//        button.sizeToFit()
//        return UIBarButtonItem(customView: button)
//    }
}
